package com.example.kai.uno.uno;

import java.util.Random;
import java.util.Vector;

import android.widget.Toast;

public class Poke {
	public static Random rand = new Random();

	public static void show(String text, int time) {
		Toast t = Toast.makeText(DDZ.ddz, text, time);
		t.show();
	}

	public static boolean inRect(int x, int y, int rectX, int rectY, int rectW,
			int rectH) {
		if (x < rectX || x > rectX + rectW || y < rectY || y > rectY + rectH) {
			return false;
		}
		return true;
	}

	// 0-53��ʾ54����
	public static void shuffle(int[] pokes) {
		int len = pokes.length;
		// ����54�����е��κ�һ�ţ��������һ�ź�������������˳����ҡ�
		for (int l = 0; l < len; l++) {
			int des = rand.nextInt(54);
			int temp = pokes[l];
			pokes[l] = pokes[des];
			pokes[des] = temp;
		}
	}




	public static void sort(int[] pokes) {
		for (int i = 0; i < pokes.length; i++) {
			for (int j = i + 1; j < pokes.length; j++) {
				if (pokes[i] < pokes[j]) {
					int temp = pokes[i];
					pokes[i] = pokes[j];
					pokes[j] = temp;
				}
			}
		}
	}

	public static boolean compare(Card f, Card s) {///////////////？？？？？？？？？？？？？
		// ������������ͬʱ
//		if (f.pokeType == s.pokeType) {
//			// ������������ͬʱ��������ͬ���޷��Ƚϣ�Ĭ��Ϊ�ڶ�����ʹs���ܳ���
//			if (f.pokes.length != s.pokes.length)
//				return false;
//			// ������ͬ��������ͬʱ���Ƚ���ֵ
//			return f.value > s.value;
//		}
//		// �����Ͳ�ͬ��ʱ��,���f�������ǻ��,�򷵻�true
//		if (f.pokeType == PokeType.huojian) {
//			return true;
//		}
//		if (s.pokeType == PokeType.huojian) {
//			return false;
//		}
//		// �ų���������ͣ�ը�����
//		if (f.pokeType == PokeType.zhadan) {
//			return true;
//		}
//		if (s.pokeType == PokeType.zhadan) {
//			return false;
//		}
//		// �޷��Ƚϵ������Ĭ��Ϊs����f
		return false;
	}
	public static int getPokeValue(int poke) {
		// ���˿�ֵΪ52ʱ����С��
		if (poke == 52) {
			return 16;
		}
		// ���˿�ֵΪ53ʱ���Ǵ���
		if (poke == 53) {
			return 17;
		}
		// ��������·�����Ӧ��ֵ(3,4,5,6,7,8,9,10,11(J),12(Q),13(K),14(A),15(2))
		return poke / 4 + 3;
	}

	public static int getImageRow(int poke) {
		return poke / 13;
	}

	public static int getImageCol(int poke) {
		return poke % 13;
	}



	public static Uno finduno(int poke){
		Uno result =null;
		if (poke==0){
			Uno uno0 =new Uno("Red",0,"null");
			uno0.setPoke(0);
		//	card.setPokeType(0);
			result=uno0;
		}
		if (poke==1){
			Uno uno1 =new Uno("Red",1,"null");
			uno1.setPoke(1);
		//	card.setPokeType(1);
			result=uno1;
		}

		if (poke==2){
			Uno uno2 =new Uno("Red",2,"null");
			uno2 .setPoke(2);
		//	card.setPokeType(2);
			result=uno2;
		}

		if (poke==3){
			Uno uno3 =new Uno("Red",3,"null");
			uno3 .setPoke(3);
		//	card.setPokeType(3);
			result=uno3;
		}
		if (poke==4){
			Uno uno4 =new Uno("Red",4,"null");
			uno4 .setPoke(4);
		//	card.setPokeType(4);
			result=uno4;
		}

		if (poke==5){
			Uno uno5 =new Uno("Red",5,"null");
			uno5 .setPoke(5);
		//	card.setPokeType(5);
			result=uno5;
		}

		if (poke==6){
			Uno uno6 =new Uno("Red",6,"null");
			uno6 .setPoke(6);
		//	card.setPokeType(6);
			result=uno6;
		}

		if (poke==7){
			Uno uno7 =new Uno("Red",7,"null");
			uno7 .setPoke(7);
		//	card.setPokeType(7);
			result=uno7;
		}

		if (poke==8){
			Uno uno8 =new Uno("Red",8,"null");
			uno8 .setPoke(8);
		//	card.setPokeType(8);
			result=uno8;
		}

		if (poke==9){
			Uno uno9 =new Uno("Red",9,"null");
			uno9 .setPoke(9);
		//	card.setPokeType(9);
			result=uno9;
		}

		if (poke==10){
			Uno uno10 =new Uno("Red",-1,"skip");
			uno10 .setPoke(10);
		//	card.setPokeType(10);
			result=uno10;
		}

		if (poke==11){
			Uno uno11 =new Uno("Red",-1,"+2");
			uno11 .setPoke(11);
		//	card.setPokeType(11);
			result=uno11;
		}

		if (poke==12){
			Uno uno12 =new Uno("Red",-1,"veer");
			uno12 .setPoke(12);
		//	card.setPokeType(12);
			result=uno12;
		}
		if (poke==13){
			Uno uno13 =new Uno("Yellow",0,"null");
			uno13 .setPoke(13);
            //	card.setPokeType(13);
			result=uno13;
		}

		if (poke==14){
			Uno uno14 =new Uno("Yellow",1,"null");
			uno14 .setPoke(14);
            //	card.setPokeType(14);
			result=uno14;
		}

		if (poke==15){
			Uno uno15 =new Uno("Yellow",2,"null");
			uno15 .setPoke(15);
            //	card.setPokeType(15);
			result=uno15;
		}

		if (poke==16){
			Uno uno16 =new Uno("Yellow",3,"null");
			uno16 .setPoke(16);
            //	card.setPokeType(16);
			result=uno16;
		}

		if (poke==17){
			Uno uno17 =new Uno("Yellow",4,"null");
			uno17 .setPoke(17);
            //	card.setPokeType(17);
			result=uno17;
		}

		if (poke==18){
			Uno uno18 =new Uno("Yellow",5,"null");
			uno18 .setPoke(18);
            //	card.setPokeType(18);
			result=uno18;
		}

		if (poke==19){
			Uno uno19 =new Uno("Yellow",6,"null");
			uno19 .setPoke(19);
            //	card.setPokeType(19);
			result=uno19;
		}

		if (poke==20){
			Uno uno20 =new Uno("Yellow",7,"null");
			uno20 .setPoke(20);
            //	card.setPokeType(20);
			result=uno20;
		}

		if (poke==21){
			Uno uno21 =new Uno("Yellow",8,"null");
			uno21 .setPoke(21);
            //	card.setPokeType(21);
			result=uno21;
		}

		if (poke==22){
			Uno uno22 =new Uno("Yellow",9,"null");
			uno22 .setPoke(22);
            //	card.setPokeType(22);
			result=uno22;
		}

		if (poke==23){
			Uno uno23 =new Uno("Yellow",-1,"skip");
			uno23 .setPoke(23);
            //	card.setPokeType(23);
			result=uno23;
		}
		if (poke==24){
			Uno uno24 =new Uno("Yellow",-1,"+2");
			uno24 .setPoke(24);
            //	card.setPokeType(24);
			result=uno24;
		}

		if (poke==25){
			Uno uno25 =new Uno("Yellow",-1,"veer");
			uno25 .setPoke(25);
            //	card.setPokeType(25);
			result=uno25;
		}
		if (poke==26){
			Uno uno26 =new Uno("Blue",0,"null");
			uno26 .setPoke(26);
            //	card.setPokeType(26);
			result=uno26;
		}

		if (poke==27){
			Uno uno27 =new Uno("Blue",1,"null");
			uno27 .setPoke(27);
            //	card.setPokeType(27);
			result=uno27;
		}

		if (poke==28){
			Uno uno28 =new Uno("Blue",2,"null");
			uno28 .setPoke(28);
            //	card.setPokeType(28);
			result=uno28;
		}

		if (poke==29){
			Uno uno29 =new Uno("Blue",3,"null");
			uno29 .setPoke(29);
            //	card.setPokeType(29);
			result=uno29;
		}

		if (poke==30){
			Uno uno30 =new Uno("Blue",4,"null");
			uno30 .setPoke(30);
            //	card.setPokeType(30);
			result=uno30;
		}

		if (poke==31){
			Uno uno31 =new Uno("Blue",5,"null");
			uno31 .setPoke(31);
            //	card.setPokeType(31);
			result=uno31;
		}

		if (poke==32){
			Uno uno32 =new Uno("Blue",6,"null");
			uno32 .setPoke(32);
            //	card.setPokeType(32);
			result=uno32;
		}

		if (poke==33){
			Uno uno33 =new Uno("Blue",7,"null");
			uno33 .setPoke(33);
            //	card.setPokeType(33);
			result=uno33;
		}

		if (poke==34){
			Uno uno34 =new Uno("Blue",8,"null");
			uno34 .setPoke(34);
            //	card.setPokeType(34);
			result=uno34;
		}

		if (poke==35){
			Uno uno35 =new Uno("Blue",9,"null");
			uno35 .setPoke(35);
            //	card.setPokeType(35);
			result=uno35;
		}

		if (poke==36){
			Uno uno36 =new Uno("Blue",-1,"skip");
			uno36 .setPoke(36);
            //	card.setPokeType(36);
			result=uno36;
		}

		if (poke==37){
			Uno uno37 =new Uno("Blue",-1,"+2");
			uno37 .setPoke(37);
            //	card.setPokeType(37);
			result=uno37;
		}

		if (poke==38){
			Uno uno38 =new Uno("Blue",-1,"veer");
			uno38 .setPoke(38);
            //	card.setPokeType(38);
			result=uno38;
		}
		if (poke==39){
			Uno uno39 =new Uno("Green",0,"null");
			uno39 .setPoke(39);
            //	card.setPokeType(39);
			result=uno39;
		}
		if (poke==40){
			Uno uno40 =new Uno("Green",1,"null");
			uno40 .setPoke(40);
            //	card.setPokeType(40);
			result=uno40;
		}

		if (poke==41){
			Uno uno41 =new Uno("Green",2,"null");
			uno41 .setPoke(41);
            //	card.setPokeType(41);
			result=uno41;
		}

		if (poke==42){
			Uno uno42 =new Uno("Green",3,"null");
			uno42 .setPoke(42);
            //	card.setPokeType(42);
			result=uno42;
		}
		if (poke==43){
			Uno uno43 =new Uno("Green",4,"null");
			uno43 .setPoke(43);
            //	card.setPokeType(43);
			result=uno43;
		}
		if (poke==44){
			Uno uno44 =new Uno("Green",5,"null");
			uno44 .setPoke(44);
            //	card.setPokeType(44);
			result=uno44;
		}

		if (poke==45){
			Uno uno45 =new Uno("Green",6,"null");
			uno45 .setPoke(45);
            //	card.setPokeType(45);
			result=uno45;
		}
		if (poke==46){
			Uno uno46 =new Uno("Green",7,"null");
			uno46 .setPoke(46);
            //	card.setPokeType(46);
			result=uno46;
		}
		if (poke==47){
			Uno uno47 =new Uno("Green",8,"null");
			uno47 .setPoke(47);
            //	card.setPokeType(47);
			result=uno47;
		}
		if (poke==48){
			Uno uno48 =new Uno("Green",9,"null");
			uno48 .setPoke(48);
            //	card.setPokeType(48);
			result=uno48;
		}
		if (poke==49){
			Uno uno49 =new Uno("Green",-1,"skip");
			uno49 .setPoke(49);
            //	card.setPokeType(49);
			result=uno49;
		}
		if (poke==50){
			Uno uno50 =new Uno("Green",-1,"+2");
			uno50 .setPoke(50);
            //	card.setPokeType(50);
			result=uno50;
		}
		if (poke==51){
			Uno uno51 =new Uno("Green",-1,"veer");
			uno51 .setPoke(51);
            //	card.setPokeType(51);
			result=uno51;
		}
		if (poke==52){
			Uno uno52 =new Uno("ALl",-1,"changecolor");
			uno52 .setPoke(52);
            //	card.setPokeType(52);
			result=uno52;
		}
		if (poke==53){
			Uno uno53 =new Uno("All",-1,"+4");
			uno53 .setPoke(53);
            //	card.setPokeType(53);
			result=uno53;
		}
		if (poke==54){
			Uno uno54 =new Uno("All",-1,"all+1");
			uno54 .setPoke(54);
            //	card.setPokeType(54);
			result=uno54;
		}
		if (poke==55){
			Uno uno55 =new Uno("All",-1,"all+2");
			uno55 .setPoke(55);
            //	card.setPokeType(55);
			result=uno55;
		}
		return result;

	}

	public static int outCardByItsself(int pokes[]) {

		int result1=-1;


		Random random=new Random();
		int ran=random.nextInt(pokes.length);
		result1=pokes[ran];
		//int[] result3=new int[]{finduno(result1).poke};
		return result1	;



	}
	private static boolean findAll(int[] poke,int function){
		boolean result=false;
		for (int i =0;i<poke.length;i++){
			if (poke[i]==function){
				result=true;
			}
		}
		return result;
	}
	public static int findfunctioncard(int[] o, int function){
		int result=-1;
		for (int i =0;i<o.length;i++){
			if (o[i]==function){
				result=o[i];
			}
		}
		return result;
	}
	// ��������
	public static int findadd4(){
		return 53;

	}
	public static int findTheRightCard(Card a, int pokes[]) {
		int num=0;
		int[] ran=new int[num];
		int result1=-1;

		if (a.poke==53){
			if (findAll(pokes,53)){
				result1=53;
			}
		}else {
				if (finduno(a.poke).function.equals("+2"))
				{
					if (findAll(pokes,11)){
						result1=11;
					}
					if (findAll(pokes,24)){
						result1=24;
					}
					if (findAll(pokes,37)){
						result1=37;
					}
					if (findAll(pokes,50)){
						result1=50;
					}
				}
				else {

			if (findAll(pokes, 52) || findAll(pokes, 53) || findAll(pokes, 54) || findAll(pokes, 55)) {
				if (findAll(pokes, 52)) {
					result1 = findfunctioncard(pokes, 52);
				}
				if (findAll(pokes, 53)) {
					result1 = findfunctioncard(pokes, 53);
				}
				if (findAll(pokes, 54)) {
					result1 = findfunctioncard(pokes, 54);
				}
				if (findAll(pokes, 55)) {
					result1 = findfunctioncard(pokes, 55);
				}

			} else {
				if (!finduno(a.poke).color.equals("All")) {
					if (finduno(a.poke).function.equals("null")) {
						if (finduno(a.poke).color.equals("Red")) {

							result1 = findrightcolor(pokes, "Red");

						}
						if (finduno(a.poke).color.equals("Green")) {
							result1 = findrightcolor(pokes, "Green");
						}
						if (finduno(a.poke).color.equals("Yellow")) {
							result1 = findrightcolor(pokes, "Yellow");
						}
						if (finduno(a.poke).color.equals("Blue")) {
							result1 = findrightcolor(pokes, "Blue");
						}
						if (finduno(a.poke).number == 0) {
							result1 = findrightnumber(pokes, 0);
						}
						if (finduno(a.poke).number == 1) {
							result1 = findrightnumber(pokes, 1);
						}
						if (finduno(a.poke).number == 2) {
							result1 = findrightnumber(pokes, 2);
						}
						if (finduno(a.poke).number == 3) {
							result1 = findrightnumber(pokes, 3);
						}
						if (finduno(a.poke).number == 4) {
							result1 = findrightnumber(pokes, 4);
						}
						if (finduno(a.poke).number == 5) {
							result1 = findrightnumber(pokes, 5);
						}
						if (finduno(a.poke).number == 6) {
							result1 = findrightnumber(pokes, 6);
						}
						if (finduno(a.poke).number == 7) {
							result1 = findrightnumber(pokes, 7);
						}
						if (finduno(a.poke).number == 8) {
							result1 = findrightnumber(pokes, 8);
						}
						if (finduno(a.poke).number == 9) {
							result1 = findrightnumber(pokes, 9);
						}
					} else {
						if (finduno(a.poke).function.equals("+2")) {
							result1 = findrightfunction(pokes, "+2");
						}
						if (finduno(a.poke).function.equals("veer")) {
							result1 = findrightfunction(pokes, "veer");
						}
						if (finduno(a.poke).function.equals("changecolor")) {
							result1 = findrightfunction(pokes, "changecolor");
						}
					}
				} else {
					if (finduno(a.poke).function.equals("+4")) {
						result1 = findrightfunction(pokes, "+4");
					}
				}
			}
		}}
		return result1;

	}
	public static int findrightcolor(int[] pokes,String color){
		int result=-1;

		for (int i=0;i<pokes.length;i++){
			if (finduno(( pokes[i])).color==null){
				result=4;
			}else {
			if (finduno(pokes[i]).color.equals(color)){
				result=pokes[i];
				break;
			}
			}}
		return result;
	}
	public static int findrightnumber(int[] pokes,int num){
		int result=-1;

		for (int i=0;i<pokes.length;i++){
			if (finduno(pokes[i]).number==num){
				result=pokes[i];
				break;
			}
		}
		return result;
	}
	public static int findrightfunction(int[] pokes,String function){
		int result=-1;

		for (int i=0;i<pokes.length;i++){
			if (finduno(pokes[i]).function.equals(function)){
				result=pokes[i];
				break;
			}
		}
		return result;
	}

	public static int colorselect(int num){
		int result = -1;
		if (num==0){
			result=0;
		}
		if (num==1){

			result=13;
		}
		if (num==2){
			result=26;
		}
		if (num==3){
			result=39;
		}
	//	int[] result3=new int[]{result};
		return result	;
	}
}
